<template>
	<view class="page" style="padding-bottom: 50rpx;">
		<view class="topVue">
			<view class="safeVue" :style="{ height: statusBarHeight + 'rpx' }"></view>
			<view class="flex align-center padding-row30" :style="{ height: barHeight + 'rpx', top: statusBarHeight + 'rpx' }" @click="$tools.back()">
				<image src="../../static/back.png" style="width: 48rpx; height: 48rpx;"></image>
				<text style="line-height: 1; color: #454545; font-weight: 600; font-size: 32rpx; padding-left: 20rpx;">分工明细</text>
				<view class="opBtn" @click.stop="show=true">公分互换</view>
			</view>
		</view>
		<view :style="{ height: statusBarHeight + barHeight + 'rpx' }"></view>
		
		<view class="item margin20 padding30" v-for="(item, index) in list" :key="index">
			<view class="li" style="padding-top: 0;">手机号：{{item.phoneNo}}</view>
			<view class="li">交易数量：{{item.num}}</view>
			<view class="li">交易前数量：{{item.before}}</view>
			<view class="li">交易后数量：{{item.after}}</view>
			<view class="li">备注：{{item.remark}}</view>
			<view class="li">时间：{{item.createTime}}</view>
		</view>
		
		<u-empty text="列表为空" mode="list" v-if="list.length===0" margin-top="200"></u-empty>
		
		<u-popup v-model="show" mode="center" @close="quantity=''; mobile=''">
			<view class="popVue padding40">
				<view class="title">公分互换</view>
				<view class="balance">公分余额： {{ user.gf }}</view>
				<view class="inpVue margin30 flex align-center">
					<view style="line-height: 1; width: 180rpx;">转公分数量</view>
					<input type="number" v-model="quantity"/>
				</view>
				<view class="inpVue margin30 flex align-center">
					<view style="line-height: 1; width: 180rpx;">接收人手机号</view>
					<input type="number" v-model="mobile"/>
				</view>
				<view class="btn margin40" @click="submit()">确定</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		data(){
			return {
				statusBarHeight: 0,
				barHeight: 0,
				menuHeight: 0,
				list: [],
				show: false,
				quantity: "",
				mobile: "",
			}
		},
		async onLoad() {
			let that = this;
			wx.getSystemInfo({
				success(res) {
					let deviceWidth = wx.getSystemInfoSync().windowWidth
					that.statusBarHeight = Number(res.statusBarHeight) * ( 750 / deviceWidth ) 
					let menuButtonInfo = wx.getMenuButtonBoundingClientRect()
					that.menuHeight = Number(menuButtonInfo.height) * ( 750 / deviceWidth )
					let barHeight = menuButtonInfo.height + (menuButtonInfo.top - res.statusBarHeight) * 2
					that.barHeight = Number(barHeight) * ( 750 / deviceWidth )
				},
			});
			await this.getList()
		},
		
		computed: {
			...mapState({
				user: state=> state.user
			})
		},
		methods: {
			async getList(){
				const res = await this.$request("/api/WeChat/workPointList", {}, 'GET')
				if(res.code===200) {
					console.log(res)
					this.list = res.data
				}
			},
			async submit(){
				if(this.user.gf<this.quantity) return this.$u.toast("余额不足")
				if(!this.quantity || this.quantity==0) return this.$u.toast("输入数量")
				if(!this.mobile) return this.$u.toast("输入接收人手机号")
				let res = await this.$request(`/api/WeChat/transferWorkPoint?number=${this.quantity}&&toPhone=${this.mobile}`, {
					number: this.quantity,
					toPhone: this.mobile
				}, "POST")
				if(res.code===0) {
					this.$u.toast("操作成功")
					this.$store.dispatch("getUser")
					this.show =false
					console.log(res)
				}else{
					this.$u.toast(res.msg)
				}
			}
		},
	}
</script>

<style lang="less" scoped>
	.topVue {
		width: 100%;
		background: #fff;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 99;
		.safeVue {
			width: 100%;
		}
		.opBtn {
			width: 150rpx;
			height: 66rpx;
			border-radius: 10rpx;
			background: #D37430;
			line-height: 66rpx;
			text-align: center;
			color: #fff;
			margin-left: 40rpx;
		}
	}
	
	.popVue {
		width: 690rpx;
		.title {
			text-align: center;
			font-weight: 600;
			font-size: 32rpx;
			color: #333;
		}
		.balance {
			color: #454545;
			padding-top: 30rpx;
			text-align: center;
		}
		input {
			flex: 1;
			height: 80rpx;
			border: 1rpx solid #f5f5f5;
			border-radius: 10rpx;
			padding-left: 20rpx;
		}
		.btn {
			width: 400rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			background: #D37430;
			border-radius: 15rpx;
			color: #fff;
		}
	}
	
	.item {
		width: 690rpx;
		background: #fff;
		border-radius: 20rpx;
		box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(178, 178, 178, 0.25), inset 0rpx 8rpx 8rpx 0rpx rgba(255, 255, 255, 0.25);
		.li {
			color: #454545;
			font-weight: 600;
			line-height: 1;
			padding-top: 20rpx;
		}
	}
</style>